package com.bdqn.carrental.controller;

import com.bdqn.carrental.pojo.CustomerEntity;
import com.bdqn.carrental.service.CustomerServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 *客户信息v
 */
@Controller //证明是controller层并且返回json
@RequestMapping(value = "/Customer")
public class CustomerController {
    @Autowired
    CustomerServiceImpl customerService;
    private String meg=null;

    /**
     * 首页进入客户展示数据
     * @param model
     * @return
     */
/*
    @RequestMapping(value = "/Customerlist",method = RequestMethod.GET)
    public String  userEntityList(Model model) {
       List<CustomerEntity> list =customerService.findAll();
       model.addAttribute("list",list);
       return "yg-jbkh";
    }
*/

    /**
     * 客户根据电话查询
     */
    @RequestMapping(value = "/CustomerPhone",method = RequestMethod.GET)
    public String  CustomerEntityList(Model model,@RequestParam(value = "phone",required=false)String phone,
                                      @RequestParam(value = "pageNum",required = false)String _pageNum ) {
        Integer pageNum=1;
        if(_pageNum!=null){
            pageNum=Integer.parseInt(_pageNum);
        }
        //引入分页查询，使用PageHelper分页功能
        //在查询之前传入当前页，然后多少记录
        PageHelper.startPage(pageNum,4);
        List<CustomerEntity> lists =customerService.SelectPhone(phone);
        //使用PageInfo包装查询结果，只需要将pageInfo交给页面就可以
        PageInfo<CustomerEntity> page=new PageInfo<CustomerEntity>(lists);
        model.addAttribute("pageInfo",page);
        model.addAttribute("meg",meg);
        model.addAttribute("phone",phone);
        meg=null;
        return "yg-jbkh";
    }
    /**
     * 下拉框查询
     */
  @RequestMapping(value = "/CustomerSe",method = RequestMethod.GET)
    public String  CustomerelectSe(Model model,@RequestParam(value = "zhi",required=false)String zhi,
                                   @RequestParam(value = "pageNum",required = false)String _pageNum) {
      Integer pageNum=1;
      if(_pageNum!=null){
          pageNum=Integer.parseInt(_pageNum);
      }
      //引入分页查询，使用PageHelper分页功能
      //在查询之前传入当前页，然后多少记录
      PageHelper.startPage(pageNum,4);
        List<CustomerEntity> lists =customerService.selectHY(zhi);
      //使用PageInfo包装查询结果，只需要将pageInfo交给页面就可以
      PageInfo<CustomerEntity> page=new PageInfo<CustomerEntity>(lists);
      model.addAttribute("zhi",zhi);
      model.addAttribute("pageInfo",page);
        return "yg-jbkh";
    }



    /**
     * 删除信息
     * @param
     * @retur
     */
    @RequestMapping(value = "/Customerdel")
    public  String del(@RequestParam(value = "PHONE") String phone){
        if(customerService.delCustomers(phone)>0){
            meg="del";
            return "redirect:/Customer/CustomerPhone";
        }
        System.out.print("删除失败");
        return "yg-jbkh";
    }

    /**
     * 修改
     * @param
     * @retur
     */
    @RequestMapping(value = "/CustomerSet")
    public  String Sets(@RequestParam(value = "PHONE") String phone){
        return "yg-xiugai";
    }

}
